<@app.html>
    <@app.head>
    <script>
        $(function () {
            $('#page_table').datagrid({
                fit: true,
                striped: true,
                url: "${contextPath}/security/hdw/report/page.htm?flag=" +${flag},
                fitColumns: true,
                singleSelect: true,
                selectOnCheck: false,
                checkOnSelect: false,
                autoRowHeight: false,
                rowStyler: gridRowStyler,
                columns: [
                    [
                        {
                            title: '运营商',
                            align: 'center',
                            field: 'agentName',
                            width: 60
                        },
                        {
                            title: '代理商',
                            align: 'center',
                            field: 'agencyName',
                            width: 60
                        },
                        {
                            title: '日期',
                            align: 'center',
                            field: 'statsDate',
                            width: 60
                        },
                        {
                            title: '总收入(元)',
                            align: 'center',
                            field: 'money',
                            width: 60,
                            formatter: function (val, row) {
                                return new Number(val / 100).toFixed(2);
                            }
                        },
                        {
                            title: '换电收入(元)',
                            align: 'center',
                            field: 'chargeMoney',
                            width: 60,
                            formatter: function (val, row) {
                                return new Number(val / 100).toFixed(2);
                            }
                        },
                        {
                            title: '订单数',
                            align: 'center',
                            field: 'orderCount',
                            width: 60
                        },
                        {
                            title: '更新时间',
                            align: 'center',
                            field: 'updateTime',
                            width: 60
                        }
                    ]
                ],
                onLoadSuccess: function () {
                    $('#page_table').datagrid('clearChecked');
                    $('#page_table').datagrid('clearSelections');
                    countTotal();
                }
            });
        })
        function countTotal() {
            var rows = $('#page_table').datagrid('getRows')//获取当前的数据行
            var totalMoney = 0, totalCount = 0;
            for (var i = 0; i < rows.length; i++) {
                totalMoney += (rows[i]['money'] || 0);
                totalCount += (rows[i]['orderCount'] || 0);
            }
            $('#countMoney').val(new Number(totalMoney / 100).toFixed(2))
            $('#countTotal').val(totalCount)
        }

        function query() {
            var datagrid = $('#page_table');
            var agentId = $('input[name="agentId"]').val();
            var agencyId = $('input[name="agencyId"]').val();
            var statsDate = $('input[name="statsDate"]').val();
            var queryParams = {
                agentId: agentId,
                agencyId: agencyId,
                statsDate: statsDate,
                flag: ${flag}
            };

            datagrid.datagrid('options').queryParams = queryParams;

            datagrid.datagrid('load');
        }
    </script>
    </@app.head>

    <@app.body>

        <@app.container>
            <@app.banner/>

        <div class="main">
            <@app.menu/>

            <div class="content" style="overflow:visible">
                <div class="panel search">
                    <div class="float_right">
                        <button class="btn btn_yellow" onclick="query()">搜索</button>
                    </div>
                    <table cellpadding="0" cellspacing="0" border="0">
                        <tr>
                            <#if Session['SESSION_KEY_USER'].type == Session['USER_TYPE_PLATFORM'].value>
                                <td align="right">运营商：</td>
                                <td>
                                    <input name="agentId" class="easyui-combotree" editable="false"
                                           style="width: 184px; height: 28px;"
                                           data-options="url:'${contextPath}/security/basic/agent/tree.htm?dummy=${'所有'?url}',method:'get',onSelect: function(rec){
                               var url = '${contextPath}/security/hdw/agency/tree.htm?dummy=${'所有'?url}&agentId='+rec.id;
                               $('#agency_id').combotree('reload', url);},
                               onChange:function(){
                               $('#agency_id').combotree('clear');}"/>
                                </td>
                            </#if>
                            <#if Session['SESSION_KEY_USER'].type == Session['USER_TYPE_AGENT'].value||Session['SESSION_KEY_USER'].type == Session['USER_TYPE_PLATFORM'].value>
                                <td align="right">代理商：</td>
                                <td>
                                    <input name="agencyId" class="easyui-combotree" editable="false" id="agency_id"
                                           data-options="url:'${contextPath}/security/hdw/agency/tree.htm?dummy=${'所有'?url}&agentId=${Session['SESSION_KEY_USER'].agentId}',method:'get'"
                                           style="width: 184px; height: 28px;"/>
                                </td>
                            </#if>
                            <td align="right">时间：</td>
                            <td>
                                <input style="height: 30px" class="easyui-datebox" editable="false" id="datetime"
                                       name="statsDate"/>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="panel grid_wrap">
                    <div class="float_right">
                        <table cellpadding="0" cellspacing="0" border="0">
                            <tr>
                                <td align="right">总收入：</td>
                                <td>
                                    <input type="text" class="text easyui-validatebox" disabled id="countMoney"/>
                                </td>
                                <td align="right">总单数：</td>
                                <td>
                                    <input type="text" class="text easyui-validatebox" disabled id="countTotal"/>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div class="grid">
                        <table id="page_table"></table>
                    </div>
                </div>
            </div>
        </div>
        </@app.container>
    </@app.body>
</@app.html>
